var e = null, a = getApp();

Page({
    data: {
        name: "",
        agent: {},
        language: "",
        activeName: "first",
        activeNameidx: 0,
        first_content: [],
        second_content: [],
        third_content: [],
        myReferral: "",
        title1: "",
        title2: "",
        title3: "",
        WeChat: "",
        phone: "",
        total: 0,
        level1: "",
        level2: "",
        level3: "",
        currentTabIndex: 0,
        is_first_content: !1,
        is_second_content: !1,
        is_third_content: !1,
        relationLevel: "",
        level1_page: 0,
        level2_page: 0,
        level3_page: 0,
        keyword: "",
        level: "",
        last_page: "",
        isShowClient: !1,
        btnShow1: !0,
        btnShow2: !0,
        btnShow3: !0,
        is_recommend_wechat: 0,
        keyword1: "",
        keyword2: "",
        keyword3: "",
        new_content: [],
        isLoadMore: !0,
        total_page: 0,
        page: 1,
        my_achievement: !1,
        isLink: !1,
        show_parents: 0,
        total_people: 0
    },
    onLoad: function(e) {
        this.pageInit(), this._getMyRelation();
    },
    pageInit: function() {
        this.setData({
            level1_page: 0,
            level2_page: 0,
            level3_page: 0,
            first_content: [],
            second_content: [],
            third_content: [],
            btnShow1: !0,
            btnShow2: !0,
            btnShow3: !0,
            keyword1: "",
            keyword2: "",
            keyword3: ""
        });
    },
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {
        var a = this;
        wx.getStorage({
            key: "yz_basic_info",
            success: function(t) {
                null !== e && clearTimeout(e), e = setTimeout(function() {
                    a.setData({
                        agent: t.data.lang.agent ? t.data.lang.agent : {},
                        name: t.data.lang.agent && t.data.lang.agent.agent ? t.data.lang.agent.agent : "客户"
                    }), wx.setNavigationBarTitle({
                        title: a.data.name
                    });
                }, 2e3);
            }
        });
    },
    onHide: function() {
        clearTimeout(e);
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    _getMyRelation: function() {
        var e = this, t = a.getNetAddresss("member.member.get-member-list");
        a._getNetWork({
            url: t,
            success: function(a) {
                var t = a.data;
                1 == t.result && (e.setData({
                    my_achievement: t.data.my_achievement,
                    myReferral: t.data.my_referral,
                    is_recommend_wechat: t.data.my_referral.is_recommend_wechat,
                    self_info: t.data.my_referral.self ? t.data.my_referral.self : {},
                    title1: t.data.my_referral.name1,
                    title2: t.data.my_referral.name2,
                    title3: t.data.my_referral.name3,
                    WeChat: parseInt(t.data.my_referral.wechat),
                    phone: parseInt(t.data.my_referral.phone),
                    realname: parseInt(t.data.my_referral.realname),
                    isLoadMore: !0,
                    total_page: 0,
                    page: 1,
                    new_content: [],
                    isShowClient: "1" == t.data.my_referral.is_show,
                    my_referral_parents: t.data.my_referral_parents,
                    isLink: !!t.data.hasOwnProperty("is_link") && t.data.is_link
                }), e._getMyAgentBaseInfo(t.data.my_agent));
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _getMyAgentBaseInfo: function(e) {
        return this.setData({
            total: e.total,
            level1: e.level1,
            level2: e.level2,
            level3: e.level3
        }), !a._isTextEmpty(this.data.level1) && this.data.level1.is_show ? (this.setData({
            activeName: "first",
            activeNameidx: 0,
            currentTabIndex: "0"
        }), void this._setDataByTabIndex()) : !a._isTextEmpty(this.data.level2) && this.data.level2.is_show ? (this.setData({
            activeName: "second",
            activeNameidx: 1,
            currentTabIndex: "1"
        }), void this._setDataByTabIndex()) : !a._isTextEmpty(this.data.level3) && this.data.level3.is_show ? (this.setData({
            activeName: "third",
            activeNameidx: 2,
            currentTabIndex: "2"
        }), void this._setDataByTabIndex()) : void 0;
    },
    _setDataByTabIndex: function() {
        "0" != this.data.currentTabIndex || this.data.is_first_content ? "1" != this.data.currentTabIndex || this.data.is_second_content ? "2" != this.data.currentTabIndex || this.data.is_third_content || (this.setData({
            is_third_content: !0,
            relationLevel: "3"
        }), this._getData()) : (this.setData({
            is_second_content: !0,
            relationLevel: "2"
        }), this._getData()) : (this.setData({
            is_first_content: !0,
            relationLevel: "1"
        }), this._getData());
    },
    goMarket: function(e) {
        if (this.data.my_achievement) {
            var a = e.currentTarget.dataset.marketid;
            wx.navigateTo({
                url: "/packageD/member/myMarket/myMarket?marketid=" + a
            });
        }
    },
    searchbtn: function(e) {
        var a = e.detail.value;
        switch (this.data.currentTabIndex) {
          case "0":
            this.setData({
                keyword1: a
            });
            break;

          case "1":
            this.setData({
                keyword2: a
            });
            break;

          case "2":
            this.setData({
                keyword3: a
            });
        }
    },
    search: function() {
        var e = this, t = 1, n = "";
        switch (this.setData({
            isLoadMore: !0,
            page: 1,
            total_page: 0
        }), this.data.currentTabIndex) {
          case "0":
            e.setData({
                relationLevel: "1"
            }), t = 1, e.setData({
                level1_page: t,
                btnShow1: !0
            }), n = e.data.keyword1;
            break;

          case "1":
            e.setData({
                relationLevel: "2"
            }), t = 1, e.setData({
                level2_page: t,
                btnShow2: !0
            }), n = e.data.keyword2;
            break;

          case "2":
            e.setData({
                relationLevel: "3"
            }), t = 1, e.setData({
                level3_page: t,
                btnShow3: !0
            }), n = e.data.keyword3;
        }
        var s = a.getNetAddresss("member.member.getMyAgentData_v2");
        s += "&relationLevel=" + e.data.relationLevel, s += "&page=" + t, s += "&keyword=" + n, 
        s += "&level=" + e.data.level, s += "&current_page=" + t, s += "&last_page=" + e.data.last_page, 
        a._getNetWork({
            url: s,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) switch (e.setData({
                    new_content: t.data.data,
                    total_page: t.data.last_page,
                    page: 1,
                    total_people: t.data.total
                }), e.data.currentTabIndex) {
                  case "0":
                    e.setData({
                        "level1.total": t.data.total
                    });
                    break;

                  case "1":
                    e.setData({
                        "level2.total": t.data.total
                    });
                    break;

                  case "2":
                    e.setData({
                        "level3.total": t.data.total
                    });
                }
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getMoreData: function() {
        var e = this, t = 1, n = "";
        switch (this.data.currentTabIndex) {
          case "0":
            e.setData({
                relationLevel: "1"
            }), t = 1, e.setData({
                level1_page: t,
                btnShow1: !0
            }), n = e.data.keyword1;
            break;

          case "1":
            e.setData({
                relationLevel: "2"
            }), t = 1, e.setData({
                level2_page: t,
                btnShow2: !0
            }), n = e.data.keyword2;
            break;

          case "2":
            e.setData({
                relationLevel: "3"
            }), t = 1, e.setData({
                level3_page: t,
                btnShow3: !0
            }), n = e.data.keyword3;
        }
        if (e.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page = this.data.page + 1;
            var s = a.getNetAddresss("member.member.getMyAgentData_v2");
            s += "&relationLevel=" + e.data.relationLevel, s += "&page=" + e.data.page, s += "&keyword=" + n, 
            s += "&level=" + e.data.level, s += "&current_page=" + e.data.page, s += "&last_page=" + e.data.last_page, 
            a._getNetWork({
                url: s,
                success: function(a) {
                    var t = a.data;
                    1 == t.result ? e.setData({
                        new_content: e.data.new_content.concat(t.data.data),
                        isLoadMore: !0
                    }) : e.setData({
                        page: e.data.page - 1,
                        isLoadMore: !1
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        }
    },
    _getData: function() {
        var e = this;
        switch (this.data.currentTabIndex) {
          case "0":
            e.setData({
                relationLevel: "1"
            });
            break;

          case "1":
            e.setData({
                relationLevel: "2"
            });
            break;

          case "2":
            e.setData({
                relationLevel: "3"
            });
        }
        var t = a.getNetAddresss("member.member.getMyAgentData_v2");
        t += "&relationLevel=" + e.data.relationLevel, t += "&page=1", t += "&keyword=" + e.data.keyword, 
        t += "&level=" + e.data.level, t += "&current_page=1", t += "&last_page=" + e.data.last_page, 
        a._getNetWork({
            url: t,
            success: function(a) {
                var t = a.data;
                1 == t.result && e.setData({
                    new_content: t.data.data,
                    page: 1,
                    total_page: t.data.last_page,
                    total_people: t.data.total
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _hidebutton: function() {
        switch (this.data.currentTabIndex) {
          case "0":
            this.setData({
                btnShow1: !1
            });
            break;

          case "1":
            this.setData({
                btnShow2: !1
            });
            break;

          case "2":
            this.setData({
                btnShow3: !1
            });
        }
    },
    handleClick: function(e) {
        var a = e.detail.index;
        0 == a ? this.setData({
            activeName: "first",
            activeNameidx: 0
        }) : 1 == a ? this.setData({
            activeName: "second",
            activeNameidx: 1
        }) : 2 == a && this.setData({
            activeName: "third",
            activeNameidx: 2
        });
        var t = "";
        switch (this.data.activeName) {
          case "first":
            t = "0";
            break;

          case "second":
            t = "1";
            break;

          case "third":
            t = "2";
        }
        this.data.currentTabIndex != t && (this.setData({
            currentTabIndex: t
        }), this.search());
    },
    handleToggle: function(e) {
        var a = e.currentTarget.dataset.item;
        wx.setClipboardData({
            data: a.wechat.toString(),
            success: function(e) {
                wx.getClipboardData({
                    success: function(e) {
                        wx.showToast({
                            icon: "none",
                            title: "已成功将" + a.nickname + "的微信号添加到剪贴板，通过微信添加朋友可加客户好友!",
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    mobilebtn: function(e) {
        var a = e.currentTarget.dataset.mobile;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    viewAmount: function(e) {
        var a = e.currentTarget.dataset;
        if (this.data.isLink) {
            var t = "/packageD/member/myRelationship/amount/amount";
            a.total && (t += "?type=total"), wx.navigateTo({
                url: t
            });
        }
    },
    viewMemberOverride: function(e) {
        if (this.data.isLink) {
            var a = e.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageD/member/myRelationship/detail/detail?member_id=" + a
            });
        }
    },
    changeSuperior: function() {
        this.setData({
            show_parents: 1 == this.data.show_parents ? 0 : 1
        });
    }
});